﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using DTN.Core;
using Hanel.DTN.News;
using VeDoThi;

public partial class Vote_Vote : System.Web.UI.Page
{
    ItblVoteCriteriaManager objVoteCri = tblVoteCriteriaManager.CreateInstance();
    ItblVotesManager objvotes = tblVotesManager.CreateInstance();
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
        string time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.000");
        DataTable dt = objvotes.SelecttblVotesDynamic_top("Top 1","[status]=1 and StartDate<='"+time+"' and EndDate>='"+time+"'", "VoteId");
        string title = dt.Rows[0]["VoteName"].ToString();

        

        DataTable dtb = objVoteCri.SelecttblVoteCriteriaDynamic("[status]=1", "VCID");
        int j = dtb.Rows.Count;
        double[] dr = new double[j];
        string[] name = new string[j];


        for (int i = 0; i < dtb.Rows.Count; i++)
        {
            dr[i] = double.Parse(dtb.Rows[i]["NumVoter"].ToString());
            name[i] = dtb.Rows[i]["VCName"].ToString();
        }



        Dothi obj = new Dothi();
        string str = obj.Pie3(dr, name, title);
       

        Label1.Text = "<script>window.onload = function (){" + str + "}</script>";

    }

    protected void LoadData()
    {
        int VCID = int.Parse(Request.QueryString["ID"].ToString());
        tblVoteCriteria voteCriteria = new tblVoteCriteria();
        voteCriteria = objVoteCri.SelecttblVoteCriteriaByID(VCID);

        int num = voteCriteria.NumVoter;
        voteCriteria.NumVoter = num + 1;
        objVoteCri.UpdatetblVoteCriteria(voteCriteria);
    }
    
}